package training;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_8_24_Training {
    //删掉一个元素以后全为 1 的最长子数组
    public int longestSubarray(int[] nums) {
        int max = 0;

        int count = 0;
        int l = 0;
        for (int r = 0; r < nums.length; r++) {
            if (nums[r] == 1) {
                max = Math.max(max, r - l);
                continue;
            }

            while (count > 0) {
                if (nums[l] == 0) {
                    count--;
                }
                l++;
            }
            max = Math.max(max, r-l);
            count++;
        }

        return max;
    }
}
